package com.ptsolusi.ceriacrudwicket.tool.pages;

import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.markup.repeater.data.DataView;

import com.ptsolusi.ceriacrudwicket.model.OrderH;
import com.ptsolusi.ceriacrudwicket.tool.dataproviders.OrderDataProvider;

public class OrderList extends BasePage {
	private static final int MAX_ITEMS_PER_PAGE = 5;

	public OrderList(){
		final WebMarkupContainer container = new WebMarkupContainer("container");
        container.setOutputMarkupId(true);
        
        OrderDataProvider provider = new OrderDataProvider();
        
        
		//list
		DataView dataView = new DataView("pageable", provider){
			
			private static final long serialVersionUID = 1L;

			@Override
			protected void populateItem(Item item) {
				final OrderH order = (OrderH) item.getModelObject();
				Label lblOrderId = new Label("lblOrderId", String.valueOf(order.getOrderId()));
				item.add(lblOrderId);
				
				Label lblCustomerName = new Label("lblCustomerName", order.getCustomer().getFirstName());
				item.add(lblCustomerName);
				
				Label lblTotal = new Label("lblTotal", order.getTotal().toEngineeringString());
				item.add(lblTotal);
				
			}
		};
		dataView.setItemsPerPage(MAX_ITEMS_PER_PAGE);
		add(dataView);
		 //add list to container so we can update it
        container.add(dataView);
        
        //add whole thing to page
        add(container);
	}
	
}
